#include "PanelItemBase.h"

//=============================================================================
// inline Implement
//=============================================================================
namespace UIStone
{
	inline CPoint FCPanelItemBase::GetItemPosition() const
	{
		return CPoint(X(), Y());
	}

	inline CSize FCPanelItemBase::GetItemSize() const
	{
		return CSize(Width(), Height());
	}

	inline void FCPanelItemBase::UpdateObject() const
	{
		CPoint pt = Item_to_TopWindow (CPoint(0,0)) ;
		::InvalidateRect(GetTopWindowHWND(), CRect(pt, GetItemSize()), FALSE) ;		
	}

	inline FCPanelItemBase* FCPanelItemBase::GetParent() const
	{
		return m_pParentItem;
	}

	inline FCPanelItemBase* FCPanelItemBase::GetTopParent() const
	{
		FCPanelItemBase* pTemp = const_cast<FCPanelItemBase*>(this);
		FCPanelItemBase* pParent = NULL;
		while (pTemp)
		{
			pParent = pTemp;
			pTemp = pTemp->GetParent();
		}
		return pParent;
	}

	inline HWND FCPanelItemBase::GetTopWindowHWND() const
	{
		return m_hTopWindow;
	}

	inline BOOL FCPanelItemBase::IsPointInObjectRect(CPoint ptWnd) const
	{
		CPoint ptHit = TopWindow_to_Item(ptWnd) ;
		return CRect(CPoint(0,0), GetItemSize()).PtInRect(ptHit) ;
	}

	inline CPoint FCPanelItemBase::Item_to_TopWindow (CPoint ptObj) const
	{
		const FCPanelItemBase* pParent = this ;
		while(pParent)
		{
			ptObj += pParent->GetItemPosition() ;
			pParent = pParent->GetParent() ;
		}
		return ptObj ;
	}

	inline CPoint FCPanelItemBase::TopWindow_to_Item (CPoint ptWnd) const
	{
		CPoint ptOri = Item_to_TopWindow(CPoint(0,0)) ;
		return (ptWnd - ptOri) ;
	}

	inline void FCPanelItemBase::OnSize (CSize NewParentSize, CSize OldParentSize)
	{

	}
};



//-----------------------------------------------------------------------------
// inline void FCPanelItemBase::HandleWindowRgnMask (FCObjImage& imgMask32)
// {
// 	CRect   rc (Item_to_TopWindow(CPoint(0,0)), CSize(Width(), Height())) ;
// 	imgMask32.BoundRect (rc) ;
// 	for (int y=rc.top ; y < rc.bottom ; y++)
// 		for (int x=rc.left ; x < rc.right ; x++)
// 		{
// 			PCL_A(imgMask32.GetBits(x,y)) = 0xFF ;
// 		}
// }
